<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/base/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>${systemOption.systemTitle}</title>
<%@ include file="/base/head.jsp"%>
<script type="text/javascript" charset="UTF-8">
	$(function() {
		$('#userlist').datagrid({
			onClickRow : function(rowIndex, rowData) {
				$('#userId').val(rowData.id);
				$('#navIds').val(rowData.navIds);
				$('#sfxt').val(rowData.sfxt);
				$("#authlist").treegrid({
					title : ' 《' + rowData.name + '》的权限',
					url : '${ctx}/json/listNav.action'
				});
				$("#authlist").treegrid('load');	
			}
		});
		$('#authlist').treegrid({
			onLoadSuccess : function(row, data) {
				var navsStr = $('#navIds').val();
				var arr = navsStr.split(",");
				if (arr.length > 0) {
					$("#authlist").treegrid('unselectAll');
					for ( var i = 0; i < arr.length; i++) {
						var idstr = arr[i];
						if (id != '') {
							var id = parseInt(idstr);
							if (!isNaN(id)) {
								$("#authlist").treegrid('select', id);
							}
						}
					}
				}
				
			}
		});
	});
	//保存
	function save_auth() {
		var sfxt = $('#sfxt').val();
		if(sfxt==1){
			$.messager.alert('友情提示', '系统管理员用户菜单权限不可修改', 'error');
			return;
		}
		var arr = $("#authlist").treegrid('getSelections');
		var ids = '';
		if(arr.length > 0) {
			for ( var i = 0; i < arr.length; i++) {
				ids = ids + arr[i].id + ',';
			}
			if (ids != '') {
				ids = ids.substr(0, ids.length - 1);
			}
		}
		
		$.messager.confirm('友情提示', '您确定授权吗？', function(r) {
			if (r) {
				$.post("${ctx}/json/saveAuth.action", {
					"id" : $('#userId').val(),
					"navIds" : ids
				}, function(data) {
					if (data) {
						$.messager.alert('友情提示', '授权成功！', 'info', function() {
							window.location.reload();
						});
					} else {
						$.messager.alert('友情提示', '授权失败', 'error');
					}

				}, "json");

			}
		})
	}
	function undo_auth() {
		$("#authlist").treegrid('reload');
	}
	function doQuery() {
		var queryParams = $('#userlist').datagrid('options').queryParams;
		queryParams.nameSch = $('#nameSch').val();
		queryParams.deptIdSch = $('#deptIdSch').combotree('getValue');
		$('#userlist').datagrid('load');

	}
</script>
</head>
<body class="easyui-layout">
	<div data-options="region:'west',iconCls:'icon-user',split:true"
		style="width:300px;">
		<table id="userlist" class="easyui-datagrid"
			data-options="fit:true,
									title:'选择用户',
									border:false,
    								rownumbers:true,
									singleSelect:true,
									striped:true,
									fitColumns:true,
									toolbar:'#tb2',
									url:'${ctx}/json/listAllUser.action'">
			<thead>
				<tr>
					<th data-options="field:'deptName',align:'left',halign:'center'" width="200"><strong>部门</strong>
					</th>
					<th data-options="field:'name',align:'left',halign:'center'" width="100"><strong>姓名</strong>
					</th>
					<th data-options="field:'id',hidden:true"></th>
					<th data-options="field:'navIds',hidden:true"></th>
					<th data-options="field:'sfxt',hidden:true"></th>
				</tr>
			</thead>
		</table>
		<div id="tb2">
			&nbsp;&nbsp;部门：<input id="deptIdSch" class="easyui-combotree"
				data-options="url:'${ctx}/json/listDept2.action',value:'0'"
				style="width:165px" /><br/> &nbsp;&nbsp;姓名：<input id="nameSch"
				class="easyui-textbox" type="text" style="width: 165px;"> &nbsp;&nbsp;<a
				href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-search',plain:true" onclick="doQuery()">查询</a>
		</div>
	</div>
	<div data-options="region:'center'">
		<div id="tabRole" class="easyui-tabs" style="width:900px;height:200px;" data-options="fit:true,border:false">
			<div title="菜单权限">
				<!-- 主窗口 -->
				<table id="authlist" class="easyui-treegrid"
									data-options="fit:true,
									animate:true,
									fitColumns:true,
									singleSelect:false,
									toolbar:'#tb',
									idField:'id',
									treeField:'text',
									cascadeCheck : true,
									deepCascadeCheck : true,
									onClickRow:function(row){
										         $(this).treegrid('cascadeCheck',{  
										         id:row.id, //节点ID  
										         deepCascade:true //深度级联  
										       });  
										 }
									">
					<thead>
						<tr>
							<th data-options="field:'ck',checkbox:true"></th>
							<th data-options="field:'text',align:'left'" width="300"><strong>菜单</strong></th>
							<th data-options="field:'id',hidden:true"></th>
						</tr>
					</thead>
					<input id="userId" name="userId" type="hidden" />
					<input id="navIds" type="hidden" />
					<input id="sfxt" type="hidden" />
				</table>
				<div id="tb">
					<a href="javascript:void(0)" onclick="save_auth()"
						class="easyui-linkbutton"
						data-options="iconCls:'icon-save',plain:true">保存</a><span
						class="vline">|</span> <a href="javascript:void(0)"
						onclick="undo_auth()" class="easyui-linkbutton"
						data-options="iconCls:'icon-undo',plain:true">取消</a>
				</div>
				<!-- 主窗口结束 -->
			
			</div>
			
		</div>

	</div>
</body>
</html>
